package com.hut.oa.model.dao.file;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.hut.oa.model.bean.Directory;
import com.hut.oa.model.bean.FileManage;
import com.hut.oa.model.bean.User;
import java.lang.String;

public interface FileManageDao  extends CrudRepository<FileManage, Long>{

	
	
	@Query("select f from FileManage f")
	List<FileManage> selectAllfile();
	
	List<FileManage> findByDirAndIsDeleteAndUser(Directory dir,Integer isdelete,User u);
	
	List<FileManage> findByDirAndIsDelete(Directory dir,Integer isdelete);
	
	@Query("update FileManage f set filename=:name where id=:id")
	@Modifying
	int updatenamebyid(@Param("name")String name,@Param("id")Long id);
	
	FileManage findById(Long id);
	
	FileManage findByIdAndFilename(Long id,String name);
	
	List<FileManage> findByDir(Directory dir);
	
	List<FileManage> findByDirAndUser(Directory dir,User user);
	@Query("update FileManage f set isDelete=:type,dir=:dir where id=:id ")
	@Modifying
	int updateisdelete(@Param("id")Long id,@Param("type")Integer type,@Param("dir")Directory dir);
	
	
	List<FileManage> findByPermissionAndIsDelete(String permission,Integer isdelete);
	
	@Query("select file  from FileManage file where permission=:permission  and filename like CONCAT('%',:filename,'%') and isDelete=0")
	List<FileManage> findlikeFilename(@Param("permission")String permission,@Param("filename")String filename);
	
	@Query("select f from FileManage f where  user=:u and suffix in('jpg','png') and isDelete=0")
	List<FileManage> selectimage(@Param("u")User u);
	
	@Query("select f from FileManage f where  user=:u and suffix in('cpp') and isDelete=0")
	List<FileManage> selecttext(@Param("u")User u);
	
	@Query("select f from FileManage f where  user=:u and suffix in('zip') and isDelete=0")
	List<FileManage> selectzip(@Param("u")User u);
	
	@Query("select f from FileManage f where  user=:u and suffix in('mp3') and isDelete=0")
	List<FileManage> selectmp3(@Param("u")User u);
	
	@Query("select f from FileManage f where  user=:u and suffix in('mp4') and isDelete=0")
	List<FileManage> selectmp4(@Param("u")User u);
	
	@Query("select file  from FileManage file where user=:user  and filename like CONCAT('%',:filename,'%') and isDelete=0")
	List<FileManage> findlikefilenameanduser(@Param("filename")String filename,@Param("user")User u);
	
	List<FileManage> findByUserAndIsDeleteAndDir(User u,Integer isdelete,Directory dir);
}
